package com.jeesite.modules.storage.api;

import com.jeesite.modules.storage.common.ServerResponse;
import com.jeesite.modules.storage.util.JPushUtil;
import com.jeesite.modules.storage.util.WebUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.UUID;

/**
 * @Author: starmile
 * @Description:
 * @Create: 2020-02-12 11:11
 **/
@RestController(value = "apijpush")
@RequestMapping(value = "/api/jpush")
public class JPushController extends APIController {
    /**
     * 快速推送全平台消息
     * @param massage 消息内容
     * @return 结果
     */
    @RequestMapping(method = RequestMethod.POST,value = "pushAll")
    @ResponseBody
    public ServerResponse<Boolean> pushAll(String massage){
        Boolean result = JPushUtil.pushAll(massage);
        return ServerResponse.createBySuccess(200, result?"推送成功":"推送失败", result);
    }

    /**
     * 推送安卓平台消息
     * @param tag
     * @param title
     * @param massage
     * @return
     */
    @RequestMapping(method = RequestMethod.POST,value = "pushAndroidTag")
    @ResponseBody
    public ServerResponse<Boolean> pushAndroidByTag(String tag, String title, String massage){
        Boolean result = JPushUtil.pushAndroidByTag(tag, title, massage);
        return ServerResponse.createBySuccess(200, result?"推送成功":"推送失败", result);
    }

    /**
     * 推送ios平台消息
     * @param tag
     * @param title
     * @param massage
     * @return
     */
    @RequestMapping(method = RequestMethod.POST,value = "pushIosTag")
    @ResponseBody
    public ServerResponse<Boolean> pushIosByTag(String tag, String title, String massage){
        Boolean result = JPushUtil.pushIosByTag(tag, title, massage);
        return ServerResponse.createBySuccess(200, result?"推送成功":"推送失败", result);
    }

    /**
     * 推送安卓平台消息
     * @param registrationId
     * @param title
     * @param massage
     * @return
     */
    @RequestMapping(method = RequestMethod.POST,value = "pushAndroid")
    @ResponseBody
    public ServerResponse<Boolean> pushAndroid(String registrationId, String title, String massage){
        Boolean result = JPushUtil.pushAndroidByRegistrationId(registrationId, title, massage);
        return ServerResponse.createBySuccess(200, result?"推送成功":"推送失败", result);
    }

    /**
     * 推送ios平台消息
     * @param registrationId
     * @param title
     * @param massage
     * @return
     */
    @RequestMapping(method = RequestMethod.POST,value = "pushIos")
    @ResponseBody
    public ServerResponse<Boolean> pushIos(String registrationId, String title, String massage){
        Boolean result = JPushUtil.pushIosByRegistrationId(registrationId, title, massage);
        return ServerResponse.createBySuccess(200, result?"推送成功":"推送失败", result);
    }

    /**
     * 获取id下的所有tag
     * @param registrationId
     * @return
     */
    @RequestMapping(method = RequestMethod.GET,value = "tag")
    @ResponseBody
    public ServerResponse<List<String>> getTags(String registrationId){
        List<String> result = JPushUtil.getTags(registrationId);
        return ServerResponse.createBySuccess(200, "", result);
    }
}
